/*
 * Created on 11/27/2012 - 11:53 PM
 */
package sembr.processing;

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;

/**
 *
 * @author adriano
 */
public class SembrProcessing 
{ 
    private String sembrPath;
    
    public SembrProcessing(String sembrPath) 
    {          
        this.sembrPath = sembrPath;
    } 
    
    /**
     * @return the sembrPath
     */
    public String getSembrPath() 
    {
        return sembrPath;
    }

    /**
     * @param sembrPath the sembrPath to set
     */
    public void setSembrPath(String sembrPath) 
    {
        this.sembrPath = sembrPath;
    }

    public void run() throws Exception 
    {
        try 
        { 
            final Process process = new ProcessBuilder("sembr.meep", getSembrPath()).start();    
            //final Process process = new ProcessBuilder("sembr.meep").start();            
            InputStream is = process.getInputStream();
            InputStreamReader isr = new InputStreamReader(is);
            BufferedReader br = new BufferedReader(isr);            
            BufferedReader bre = new BufferedReader(new InputStreamReader(process.getErrorStream()));            
            String line;
           
            while ((line = br.readLine()) != null) 
            {
                System.out.println("correct: " + line);
            }
                        
            while ((line = bre.readLine()) != null) 
            {
                System.out.println("incorrect: " + line);
            }
                        
            System.out.println("Meep execution finished.");
        } 
        catch (IOException e) 
        { 
            System.out.println("IO error: " + e.getMessage());
        }       
    }
    
//    public static void main(String args[]) 
//    {
//        SembrProcessing processing = new SembrProcessing("home/adriano/Projects/SEM-BR/trunk/");
//        processing.execute();
//    }   
}
